bloatpad: use Gtk's automated menu loading
authorRyan Lortie <desrt@desrt.ca>
Fri, 4 Jul 2014 13:46:57 +0000 (09:46 -0400)
committerRyan Lortie <desrt@desrt.ca>
Mon, 7 Jul 2014 18:46:28 +0000 (14:46 -0400)
We move our menus.ui file into Gtk's namespace so that it will get
picked up.  Accordingly, we no longer have to do any of the work for
ourselves...

https://bugzilla.gnome.org/show_bug.cgi?id=722092

examples/bp/Makefile.am
examples/bp/bloatpad.c
examples/bp/bloatpad.gresources.xml
examples/bp/gtk/menus.ui [new file with mode: 0644]
examples/bp/menus.ui [deleted file]

index 827432d258b0ba16c18725bc46520320a1bdaf20..ed1a486af02dfc3b13fee8e0ccf0a45137c3ca77 100644 (file)
@@ -19,7 +19,7 @@ nodist_bloatpad_SOURCES = bloatpad-gresources.c
 
 resource_files = \
        bloatpad.gresources.xml         \
-       menus.ui
+       gtk/menus.ui
 
 bloatpad-gresources.c: $(resource_files)
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source $<
index c0e2d7d5073d0f64b875acc082a3c4f2a70515d4..1ca129ec97b63d602f57d2b695e4ff5e1362e632 100644 (file)
@@ -509,7 +509,6 @@ bloat_pad_startup (GApplication *application)
 {
   BloatPad *bloatpad = (BloatPad*) application;
   GtkApplication *app = GTK_APPLICATION (application);
-  GtkBuilder *builder;
   GMenu *menu;
   GMenuItem *item;
   GIcon *icon;
@@ -537,13 +536,10 @@ bloat_pad_startup (GApplication *application)
 
   g_action_map_add_action_entries (G_ACTION_MAP (application), app_entries, G_N_ELEMENTS (app_entries), application);
 
-  builder = gtk_builder_new_from_resource ("/org/gtk/bloatpad/menus.ui");
-  gtk_application_set_app_menu (app, G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
-  gtk_application_set_menubar (app, G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
   for (i = 0; i < G_N_ELEMENTS (accels); i++)
     gtk_application_set_accels_for_action (app, accels[i].action_and_target, accels[i].accelerators);
 
-  menu = G_MENU (gtk_builder_get_object (builder, "icon-menu"));
+  menu = gtk_application_get_menu_by_id (GTK_APPLICATION (application), "icon-menu");
 
   file = g_file_new_for_path (SRCDIR "/../gtk/stock-icons/16/help-about.png");
   icon = g_file_icon_new (file);
@@ -609,8 +605,7 @@ bloat_pad_startup (GApplication *application)
 
   dump_accels (GTK_APPLICATION (application));
   //gtk_application_set_menubar (GTK_APPLICATION (application), G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
-  bloatpad->time = G_MENU (gtk_builder_get_object (builder, "time-menu"));
-  g_object_unref (builder);
+  bloatpad->time = gtk_application_get_menu_by_id (GTK_APPLICATION (application), "time-menu");
 }
 
 static void
index beee6b27e02930266213f18a9b8cae94b2a1f386..2e5c42314b09193b9750647af6bb231cd1228c2d 100644 (file)
@@ -2,6 +2,6 @@
 
 <gresources>
   <gresource prefix="/org/gtk/bloatpad">
-    <file preprocess="xml-stripblanks">menus.ui</file>
+    <file preprocess="xml-stripblanks">gtk/menus.ui</file>
   </gresource>
 </gresources>
diff --git a/examples/bp/gtk/menus.ui b/examples/bp/gtk/menus.ui
new file mode 100644 (file)
index 0000000..a05986f
--- /dev/null
@@ -0,0 +1,83 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<interface>
+  <menu id='app-menu'>
+    <section>
+      <item>
+        <attribute name='label' translatable='yes'>_New Window</attribute>
+        <attribute name='action'>app.new</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name='label' translatable='yes'>_About Bloatpad</attribute>
+        <attribute name='action'>app.about</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name='label' translatable='yes'>_Quit</attribute>
+        <attribute name='action'>app.quit</attribute>
+      </item>
+    </section>
+  </menu>
+  <menu id='menubar'>
+    <submenu>
+      <attribute name='label' translatable='yes'>_Edit</attribute>
+      <section>
+        <item>
+          <attribute name='label' translatable='yes'>_Copy</attribute>
+          <attribute name='action'>win.copy</attribute>
+        </item>
+        <item>
+          <attribute name='label' translatable='yes'>_Paste</attribute>
+          <attribute name='action'>win.paste</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <!-- action should never be missing (so always shown) -->
+          <attribute name='label'>Clear (always shown)</attribute>
+          <attribute name='action'>win.clear</attribute>
+          <attribute name='hidden-when'>action-missing</attribute>
+        </item>
+        <item>
+          <attribute name='label'>Clear (hidden when no text)</attribute>
+          <attribute name='hidden-when'>action-disabled</attribute>
+          <attribute name='action'>win.clear</attribute>
+        </item>
+        <item>
+          <attribute name='label'>Spell check (does nothing, hides)</attribute>
+          <attribute name='hidden-when'>action-missing</attribute>
+          <attribute name='action'>win.spell-check</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name='label' translatable='yes'>Accelerators...</attribute>
+          <attribute name='action'>app.edit-accels</attribute>
+        </item>
+      </section>
+    </submenu>
+    <submenu>
+      <attribute name='label' translatable='yes'>_View</attribute>
+      <section>
+        <item>
+          <attribute name='label' translatable='yes'>_Fullscreen</attribute>
+          <attribute name='action'>win.fullscreen</attribute>
+        </item>
+        <item>
+          <attribute name='label' translatable='yes'>_Look Busy</attribute>
+          <attribute name='action'>win.busy</attribute>
+        </item>
+      </section>
+    </submenu>
+    <submenu id='icon-menu'>
+      <attribute name='label' translatable='yes'>_Icons</attribute>
+    </submenu>
+    <submenu id='time-menu'>
+      <attribute name='label' translatable='yes'>Time</attribute>
+      <attribute name='submenu-action'>app.time-active</attribute>
+    </submenu>
+  </menu>
+</interface>
diff --git a/examples/bp/menus.ui b/examples/bp/menus.ui
deleted file mode 100644 (file)
index a05986f..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-
-<interface>
-  <menu id='app-menu'>
-    <section>
-      <item>
-        <attribute name='label' translatable='yes'>_New Window</attribute>
-        <attribute name='action'>app.new</attribute>
-      </item>
-    </section>
-    <section>
-      <item>
-        <attribute name='label' translatable='yes'>_About Bloatpad</attribute>
-        <attribute name='action'>app.about</attribute>
-      </item>
-    </section>
-    <section>
-      <item>
-        <attribute name='label' translatable='yes'>_Quit</attribute>
-        <attribute name='action'>app.quit</attribute>
-      </item>
-    </section>
-  </menu>
-  <menu id='menubar'>
-    <submenu>
-      <attribute name='label' translatable='yes'>_Edit</attribute>
-      <section>
-        <item>
-          <attribute name='label' translatable='yes'>_Copy</attribute>
-          <attribute name='action'>win.copy</attribute>
-        </item>
-        <item>
-          <attribute name='label' translatable='yes'>_Paste</attribute>
-          <attribute name='action'>win.paste</attribute>
-        </item>
-      </section>
-      <section>
-        <item>
-          <!-- action should never be missing (so always shown) -->
-          <attribute name='label'>Clear (always shown)</attribute>
-          <attribute name='action'>win.clear</attribute>
-          <attribute name='hidden-when'>action-missing</attribute>
-        </item>
-        <item>
-          <attribute name='label'>Clear (hidden when no text)</attribute>
-          <attribute name='hidden-when'>action-disabled</attribute>
-          <attribute name='action'>win.clear</attribute>
-        </item>
-        <item>
-          <attribute name='label'>Spell check (does nothing, hides)</attribute>
-          <attribute name='hidden-when'>action-missing</attribute>
-          <attribute name='action'>win.spell-check</attribute>
-        </item>
-      </section>
-      <section>
-        <item>
-          <attribute name='label' translatable='yes'>Accelerators...</attribute>
-          <attribute name='action'>app.edit-accels</attribute>
-        </item>
-      </section>
-    </submenu>
-    <submenu>
-      <attribute name='label' translatable='yes'>_View</attribute>
-      <section>
-        <item>
-          <attribute name='label' translatable='yes'>_Fullscreen</attribute>
-          <attribute name='action'>win.fullscreen</attribute>
-        </item>
-        <item>
-          <attribute name='label' translatable='yes'>_Look Busy</attribute>
-          <attribute name='action'>win.busy</attribute>
-        </item>
-      </section>
-    </submenu>
-    <submenu id='icon-menu'>
-      <attribute name='label' translatable='yes'>_Icons</attribute>
-    </submenu>
-    <submenu id='time-menu'>
-      <attribute name='label' translatable='yes'>Time</attribute>
-      <attribute name='submenu-action'>app.time-active</attribute>
-    </submenu>
-  </menu>
-</interface>